package com.yc.tomcat.impl;

import com.yc.tomcat.HttpSession;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class HttpSessionImpl implements HttpSession {

   long creationTime= System.currentTimeMillis();
   String id= UUID.randomUUID().toString();
   Map<String,Object> attributeMap=new HashMap<>();


    @Override
    public long getCreationTime() {
        return creationTime;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public long getLastAccessedTime() {
        return 0;
    }

    @Override
    public int getMaxInactiveInterval() {
        return 30;
    }

    @Override
    public void invalidate() {

        HttpServletRequsetImpl.sessionMap.remove(this.id);

   /*     String id= UUID.randomUUID().toString(); //每次产生的session不同
        this.id=id;
        attributeMap.clear();*/
    }

    @Override
    public void setAttribute(String name, Object value) {
     attributeMap.put(name, value);
    }

    @Override
    public Object getAttribute(String name) {
        return attributeMap.get(name);
    }

    @Override
    public void removeAttribute(String name) {
            attributeMap.remove(name);
    }
}
